package com.design.strategy.passport.adapterv2;


import com.design.strategy.passport.ResultMsg;
import com.design.strategy.passport.adapterv2.adapters.*;

public class PassportForThirdAdapter implements IPassportForThird {
    @Override
    public ResultMsg loginForQQ(String openId) {
        return processLogin(openId,new LoginForQQAdapter());
    }

    @Override
    public ResultMsg loginForWechat(String openId) {
        return processLogin(openId, new LoginForWechatAdapter());
    }

    @Override
    public ResultMsg loginForToken(String token) {
        return processLogin(token,new LoginForTokenAdapter());
    }

    @Override
    public ResultMsg loginForTelPhone(String phone, String code) {
        return processLogin(phone,new LoginForTelAdapter());
    }


    private ResultMsg processLogin(String id,ILoginAdapter adapter) {
        try {

//           ILoginAdapter adapter = clazz.newInstance();
            if (adapter.support(adapter)) {
                return adapter.login(id, adapter);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }


}
